<template>
  <div class="tab-bar-item" @click="item_click">
    <div v-if="!isActive">
      <slot name="icon"></slot>
    </div>
    <div v-else>
      <slot name="icon_active"></slot>
    </div>
    <div :style="activeStyle">
      <slot name="icon_text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabbarItem",
  props: {
    link: {
      type: String,
      defualt: "",
    },
    active_color: {
      type: String,
      defualt: "red",
    },
  },
  methods: {
    item_click() {
      this.$router.replace(this.link);
    },
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.link) !== -1;
    },
    activeStyle() {
      return this.isActive ? { color: this.active_color } : {};
    },
  },
};
</script>

<style scoped>
.tab-bar-item {
  flex: 1;
  text-align: center;
  /* tab-bar高度一般49px */
  height: 49px;
  line-height: 49px;
}
.tab-bar-item img {
  height: 24px;
}
.tab-bar-item div div {
  margin-top: -35px;
  font-size: var(--font-size);
}
</style>
